package com.wxapp.system.service.service.impl;

import com.wxapp.common.constant.base.IBaseService;
import com.wxapp.common.constant.pojo.vm.ResultVm;
import com.wxapp.common.constant.pojo.vo.UserVo;
import com.wxapp.system.service.service.UploadService;
import com.wxapp.system.service.util.MinioUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

/**
 * @author lgl
 * @Description 上传
 * @Datetime 2022/8/25 18:12
 * @Modified By
 */
@Service
@RequiredArgsConstructor
public class UploadServiceImpl extends IBaseService implements UploadService {
    private final MinioUtil minioUtil;

    @Override
    public ResultVm<String> upload(UserVo userVo, MultipartFile file, String path) {
        try {
            return success("上传成功",minioUtil.upload(file, path));
        } catch (Exception e) {
            return error("上传失败:" + e.getMessage());
        }
    }
    @Override
    public ResultVm<String> tempUrl(String name) throws Exception {
        return success(minioUtil.getObjectUrl(name));
    }

    @Override
    public ResultVm<String> delFile(String name) {
        try {
            minioUtil.removeObject(name);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return success();
    }
}
